﻿using System;
using System.IO;

namespace woaC2.Common
{
    /// <summary>
    /// Ghi Chép
    /// </summary>
    public class Log
    {

        public static void WriteOnScreen1(string str, params object[] par)
        {   
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine(str,par);
            Console.ForegroundColor = ConsoleColor.DarkGray;
        }

        public static void WriteOnScreen2(string str, params object[] par)
        {
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(str, par);
            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.Write(">>");
        }

        public static void WriteError(string str, params object[] par)
        {
            string dirPath = Directory.GetCurrentDirectory() + @"\Log\" + DateTime.Now.ToString("dd-MM-yy");

            if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath);

            string filePath = dirPath + @"\Error.txt";

            StreamWriter fileWriter = null;

            if (File.Exists(filePath))
                fileWriter = File.AppendText(filePath);
            else
                fileWriter = File.CreateText(filePath);

            try
            {
                fileWriter.Write("[" + DateTime.Now + "]:ERROR--" + str, par);
                fileWriter.WriteLine();
                fileWriter.WriteLine();
            }
            finally
            {
                fileWriter.Close();
            }

        }

        public static void WriteTrace(string str, params object[] par)
        {
            string dirPath = Directory.GetCurrentDirectory() + @"\Log\" + DateTime.Now.ToString("dd-MM-yy");

            if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath);

            string filePath = dirPath + @"\Trace.txt";

            StreamWriter fileWriter = null;

            if (File.Exists(filePath))
                fileWriter = File.AppendText(filePath);
            else
                fileWriter = File.CreateText(filePath);

            try
            {
                fileWriter.Write("[" + DateTime.Now + "]:TRACE--" + str, par);
                fileWriter.WriteLine();
                fileWriter.WriteLine();
            }
            finally
            {
                fileWriter.Close();
            }

        }

    }
}
